package jdbc;

import util.DBUtil;

import java.sql.*;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Fenye {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        System.out.println("一页多少条：");
        int pageSize=in.nextInt();
        System.out.println("查看第几页：");
        int pageNo=in.nextInt();

        String sql="select * from s_student order by stuno desc limit ?,?";
        Connection connection = DBUtil.get();
        PreparedStatement ps = null;
        ResultSet rs = null;
            try {
            ps = connection.prepareStatement(sql);
            ps.setInt(1,(pageNo-1)*pageSize);
            ps.setInt(2,pageSize);
            rs = ps.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getLong("stuno"));
                System.out.println(rs.getString("sname"));
                Date enterdate = rs.getDate("enterdate");
                System.out.println("入学时间："+enterdate);
                System.out.println(">>>>>>>>>>>>>>>>>>>");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rs,ps,connection);
        }
    }
}
